<div class="conter_box box_dingding">
    <!-- <div style="padding-bottom: 12px; margin-bottom: 18px; border-bottom: #ccc 1px dashed;">
        <div class="flex" style="align-item: center; height: 32px;">
            <span class="tname" style="width: 99px; line-height: 30px; padding-right: 20px; text-align: right;"><i class="total_tips">?</i>设为默认</span>
            <div>
                <input class="btswitch btswitch-ios" id="default_setting" type="checkbox" />
                <label style="position: relative;top: 5px;" class="btswitch-btn" for="default_setting"></label>
            </div>
        </div>
    </div> -->
    <div class="bt-form">
        <div class="line">
            <span class="tname">Notify everyone</span>
            <div class="info-r" style="height:28px; margin-left:125px">
                <input class="btswitch btswitch-ios" id="panel_alert_all" type="checkbox" disabled="disabled" checked>
                <label style="position: relative;top: 5px;" title="Only supports notify everyone." class="btswitch-btn" for="panel_alert_all"></label>
            </div>
        </div>
        <div class="line">
            <span class="tname">Dingding URL</span>
            <div class="info-r">
                <textarea name="channel_dingding_value" class="bt-input-text mr5" type="text" placeholder="Please enter Dingding url" style="width: 300px; height:90px; line-height:20px"></textarea>
            </div>
            <button class="btn btn-success btn-sm dingding_submit" style="margin: 10px 0 0 125px;">Save</button>
        </div>
        <div class="line">
            <ul class="help-info-text c7">
                <li>Notify everyone, Immutable</li>
            </ul>
        </div>
    </div>
</div>
<style type="text/css">
.total_tips {
    border: 1px solid #cbcbcb;
    border-radius: 8px;
    color: #cbcbcb;
    cursor: pointer;
    display: inline-block;
    font-family: arial;
    font-size: 12px;
    font-style: normal;
    height: 14px;
    line-height: 14px;
    margin-right: 5px;
    text-align: center;
    width: 14px;
}
</style>
<!--钉钉模块-->
<script type="text/javascript">
    var dingding = {
        all_info: {},
        init: function () {
            var that = this;
            this.all_info = $('.alarm-view .bt-w-menu p.bgw').data('data'); //设置全局数据
            this.get_dingding_data();

             // 设置默认
            $('#default_setting').change(function () {
                var _default = $(this).prop('checked');
                var _url = that.all_info.data.dingding_url;
                if (!_url) {
                    layer.msg('Dingding URL is not configured', { icon: 2 })
                    $(this).prop('checked', !_default);
                    return
                }
                var loadTs = layer.msg('Dingding configuration is being set, please wait...', { icon: 16, time: 0, shade: [0.3, '#000'] });
                $.post('/config?action=set_default_channel&channel=dingding', { default: _default }, function (res) {
                    layer.close(loadTs);
                    layer.msg(res.msg, { icon: res.status ? 1 : 2 })
                    if (res.status) that.refresh_data();
                });
            });

            var showTips = ''
            $('.total_tips').hover(function(){
                showTips = setTimeout(function(){
                    layer.tips('After setting as default, message notifications will be sent using this message channel first.', $('.total_tips'), {
                        tips: [1, '#20a53a'],
                        time: 0,
                        success:function(layero,indexs){
                            layero.css("left", $('.total_tips').offset().left - 10);
                    }})
                },200)
            },function(){
                clearTimeout(showTips);
                layer.closeAll('tips');
            })
        },
        /**
            *@description 获取钉钉url，保存按钮添加事件
        */
        get_dingding_data: function () {
            var that = this;
            var data = this.all_info.data;

            if (data) {
                var url = data.dingding_url || '';
                var _default = data.hasOwnProperty('default') ? data.default : false

                $('textarea[name=channel_dingding_value]').val(url);
                $('#default_setting').prop('checked', _default);
            }
            // 钉钉信息设置
            $('.dingding_submit').click(function () {
                that.set_submit_ding();
            })
        },
        /**
            *@description 设置钉钉url信息，保存按钮
        */
        set_submit_ding: function () {
            var that = this;
            var _url = $('textarea[name=channel_dingding_value]').val();
            if (_url == '') return layer.msg('Please enter Dingding url', { icon: 2 })
            var loadT = layer.msg('Dingding is being set up, please wait...', { icon: 16, time: 0, shade: [0.3, '#000'] });
            $.post('/config?action=set_msg_config&name=dingding', { url: _url, atall: 'True' }, function (rdata) {
                layer.close(loadT);
                layer.msg(rdata.msg, { icon: rdata.status ? 1 : 2 })
                if (rdata.status) that.refresh_data();
            })
        },
        refresh_data: function () {
            var that = this
            $.post('/config?action=get_msg_configs', function (rdata) {
                $.each(rdata, function (key, item) {
                    var $el = $('.alarm-view .bt-w-menu .men_' + key);
                    if (item.data && item.data.default) {
                        $el.html($el.text() + '<span class="show-default"></span>');
                    } else {
                        $el.find('span').remove();
                    }
                    $el.data('data', item);
                    if (key === 'dingding') {
                        that.all_info = item
                    }
                });
            })
        }
    }

</script>